package cn.tedu.ex;

import java.util.Arrays;
import java.util.Random;

//测试 冒泡排序
public class Test1_Bubble {
    public static void main(String[] args) {
        //定义无序数组
        int[] a = {96,85,32,56,18};
        //冒泡排序
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    int t = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = t;
                }
            }
        }
        System.out.println(Arrays.toString(a));
        int[] b = randomArr(10);
        System.out.println(Arrays.toString(b));
    }
    /**
     *这个方法用来产生指定长度的随机数组
     * @param lenth 数组的长度
     * @return 随机数组
     */
    public static int[] randomArr(int lenth){
        int[] arr = new int[lenth];
        for (int i = 0; i < lenth; i++) {
            arr[i] = new Random().nextInt(100);
        }
        return arr;
    }
}
